<!--{template lyear:header_simple_start}-->
<link href="{MOD_PATH}/images/lyear_comment.css?{VERHASH}" rel="stylesheet" media="all">
<link href="static/css/smilies.css?{VERHASH}"rel="stylesheet" media="all">
<link rel="stylesheet" href="static/lyear/js/layui/css/layui.css?{VERHASH}">
<link href="static/dzzthumb/jquery.dzzthumb.css?{VERHASH}" rel="stylesheet" media="all">
<script type="text/javascript" src="static/dzzthumb/jquery.dzzthumb.js?{VERHASH}"></script>
<!--{template lyear:header_simple_end}-->
<main class="bs-main-container">
	<div class="container-fluid">
		<div class="card">
			<div class="card-body">
				<div class="card-search mb-2-5">
					  <div class="row">
						<div class="col-md-4">
						  <div class="row">
							<label class="col-sm-4 col-form-label">内容</label>
							<div class="col-sm-8">
							  <input type="text" class="form-control pull-left" name="keyword" id="keyword" placeholder="{lang please_enter_comment}">
							</div>
						  </div>
						</div>
						<div class="col-md-4">
						  <button type="submit" class="btn btn-primary me-1" id="search-btn">搜索</button>
						  <button type="reset" class="btn btn-default" id="refreshsearch">重置</button>
						</div>
					  </div>
				  </div>
				<table class="layui-hide" id="table" lay-filter="table"></table>
				<script type="text/html" id="toolbar">
					<div class="layui-btn-container">
						<button type="button"  class="layui-btn layui-btn-normal layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
						<button type="button" class="layui-btn layui-btn-danger layui-btn-sm" lay-event="delete">{lang delete}</button>
						<button type="button" class="layui-btn layui-btn-normal layui-btn-sm" lay-event="get">刷新</button>
					</div>
				</script>
				<script type="text/html" id="barDemo">
					<a class="btn btn-sm btn-primary me-1" title="{lang view}当前评论" lay-event="view"><i class="mdi mdi-magnify-expand"></i></a>
					<a class="btn btn-sm btn-outline-info me-1 " title="{lang view}所有评论" lay-event="viewid"><i class="mdi mdi-comment-text-multiple"></i></a>
					<a class="btn btn-sm btn-outline-primary me-1" title="{lang edit}" lay-event="edit"><i class="mdi mdi-pencil"></i></a>
					<a class="btn btn-sm btn-outline-danger" title="{lang delete}" lay-event="del"><i class="mdi mdi-delete"></i></a>
				</script>
			</div>
		</div>
	</div>
</main>
<script src="static/lyear/js/layui/layui.js?{VERHASH}"></script>
<script>
	var type = '';
	layui.use('table', function(){
	  var table = layui.table;
	  table.render({
		elem: '#table',
		url: '{MOD_URL}&do=getinfo',
		title: '评论管理数据表格',
		toolbar: '#toolbar',
		autoSort: false,
		even:true,
		cellMinWidth:120,
		text: {
			none: '暂无相关数据'
		},
		page: {
		  limit: 20,
		  limits: [10, 20, 50, 100, 200, 500, 1000,2000,5000]
		},
		cols: [[
		{type:'checkbox', fixed: 'left'}
		,{title: 'ID',width:80, fixed: 'left',type: 'numbers'}
		  ,{field:'dateline', title: '评论时间', align: 'center', sort: true}
		  <!--{if $_G['adminid']}-->,{field:'authorid', title: '评论者', align: 'center', sort: true}
		  ,{field:'edituid', title: '编辑者', align: 'center', sort: true}
		  ,{field:'edittime', title: '编辑时间', align: 'center', sort: true}<!--{/if}-->
		  ,{field:'ip', title: 'IP', align: 'center', sort: true}
		  ,{field:'xtllq', title: '{lang Equipment information}', align: 'center', sort: true}
		  ,{field:'message', title: '评论内容', align: 'center', sort: true}
		  ,{title: '{lang operation}',width:200, align:'center', toolbar: '#barDemo', fixed: 'right'}
		]],
		initSort: {
			field: 'dateline', // 默认排序字段
			type: 'desc' // 默认排序方式
		}
	  });
	  //头工具栏事件
	table.on('toolbar(table)', function(obj){
		var checkStatus = table.checkStatus(obj.config.id); //获取选中行状态
		var data = checkStatus.dataCache;
		switch(obj.event){
			case 'getCheckData':
				if (data.length === 0) {
					showmessage("请至少选择一行", 'danger', 3000, 1);
					return;
				}
				var template = '<div class="accordion">';
				data.forEach(function(item) {
					template += '<div class="accordion-item">';
					template += '<h2 class="accordion-header" id="Open-heading' + item.LAY_NUM + '">';
					template += '<button class="accordion-button" type="button" data-toggle="collapse" data-target="#Open-collapse' + item.LAY_NUM + '" aria-expanded="true" aria-controls="Open-collapse' + item.LAY_NUM + '">';
					template += 'ID：' + item.LAY_NUM;
					template += '</button>';
					template += '</h2>';
					template += '<div id="Open-collapse' + item.LAY_NUM + '" class="accordion-collapse collapse show" aria-labelledby="Open-heading' + item.LAY_NUM + '">';
					template += '<div class="accordion-body">';
					<!--{if $_G['adminid']}-->
					template += '<p><strong>评论者:</strong> ' + item.authorid + '</p>';
					<!--{/if}-->
					template += '<p><strong>评论时间:</strong> ' + item.dateline + '</p>';
					<!--{if $_G['adminid']}-->
					if (item.edituid) {
						template += '<p><strong>{lang 编辑者}:</strong> ' + item.edituid + '</p>';
					}
					if (item.edittime) {
						template += '<p><strong>{lang 编辑时间}:</strong> ' + item.edittime + '</p>';
					}
					<!--{/if}-->
					if (item.ip) {
						template += '<p><strong>{lang IP}:</strong> ' + item.ip + '</p>';
					}
					if (item.xtllq) {
						template += '<p><strong>{lang Equipment information}:</strong> ' + item.xtllq + '</p>';
					}
					if (item.message) {
						template += '<p><strong>评论内容:</strong> ' + item.message + '</p>';
					}
					template += '</div>';
					template += '</div>';
					template += '</div>';
				});
				template += '</div>';
				layer.alert(template, {
					title: '选中的评论列表'
				});
				break;
				case 'delete':
					if (data.length === 0) {
						showmessage("请至少选择一行", 'danger', 3000, 1);
						return;
					}
					var postData = "";
					$.each(data,function(i) {
						postData +=  this.rid;
						if (i < data.length - 1) {
							postData += ",";
						}
					});
					layer.confirm('你确定要删除'+data.length+'条评论吗(如果有回复评论也将一同删除)？', function(index){
						var loading = layer.load(0, { shade:  [0.1, '#000'] });
						jQuery.post('{MOD_URL}&do=delete', {'cid': postData},function(json){
							layer.close(loading);
							layer.close(index);
							if(json['msg']=='success'){
								showmessage('删除成功', 'success', '3000', 1);
								table.reloadData('table');
								return false;
							}else if(json['msg']){
								showmessage(json['msg'], 'danger', '3000', 1);
							} else {
								showmessage('{lang error}', 'danger', '3000', 1);
							}
							},'json')
							.fail(function() {
								layer.close(loading);
								layer.close(index);
								showmessage('服务器发生错误，请稍后再试', 'danger',3000,1);
					});
					});
				break;
				case 'get':
					table.reloadData('table', {
						where: {type: type}, // 清空搜索参数
						page: {
							curr: 1 //重新从第 1 页开始
						}
					});
				break; 
			};
		});
	  //监听工具条
	  table.on('tool(table)', function(obj){
		var data = obj.dataCache;
		if(obj.event === 'edit'){
			showWindow('publish_edit_'+data.cid,'{MOD_URL}&op=ajax&do=edit&template=1&cid='+data.cid+'&allowattach=3&allowat=1&allowsmiley=1','get',0,'',1);
		} else if(obj.event === 'del'){
			layer.confirm('你确定要删除这条评论吗(如果有回复评论也将一同删除)？', function(index){
				var loading = layer.load(0, { shade:  [0.1, '#000'] });
				$.ajax({
					type: "post",
					url: "{MOD_URL}&op=ajax&do=delete",
					data: {cid: data.cid},
					dataType: 'json',
					success: function (res, status) {
						layer.close(index);
						layer.close(loading);
						if (res.msg == 'success') {
							showmessage('删除成功', 'success',3000,1);
							obj.del();
						} else {
							showmessage(res.msg, 'danger',3000,1);
						}
					},
					error: function () {
						layer.close(index);
						layer.close(loading);
						showmessage('服务器发生错误，请稍后再试', 'danger',3000,1);
					}
				});
			});
		} else if(obj.event === 'view'){
			showWindow('publish_view_'+data.cid,'{MOD_URL}&op=ajax&do=getcommentbycid&template=1&modal=1&cid='+data.cid+'&allowattach=3&allowat=1&allowsmiley=1','get',0,'',1);
		} else if(obj.event === 'viewid'){
			showWindow('publish_view_'+data.fid,'{MOD_URL}&op=ajax&do=getcomment&template=1&modal=1&idtype='+data.idtype+'&id='+data.fid+'&allowattach=3&allowat=1&allowsmiley=1','get',0,'',1);
		}
	  });
	    //触发排序事件 
	table.on('sort(table)', function(obj){
			table.reloadData('table', {
				initSort: obj
				,where: {
					field: obj.field
					,order: obj.type
				}
			});
		});
	  table.on('rowDouble(table)', function(obj){
		showDataTemplate(obj);
	  });
		function showDataTemplate(obj) {
			var data = obj.dataCache;
			var template = '';
			<!--{if $_G['adminid']}-->
			if (data.authorid) {
				template += '<p><strong>评论者:</strong> ' + data.authorid + '</p>';
			}
			<!--{/if}-->
			if (data.dateline) {
				template += '<p><strong>评论时间:</strong>' + data.dateline + '</p>';
			}
			<!--{if $_G['adminid']}-->
			if (data.edituid) {
				template += '<p><strong>编辑者:</strong> ' + data.edituid + '</p>';
			}
			if (data.edittime) {
				template += '<p><strong>编辑时间:</strong>' + data.edittime + '</p>';
			}
			<!--{/if}-->
			if (data.ip) {
				template += '<p><strong>IP:</strong> ' + data.ip + '</p>';
			}
			if (data.xtllq) {
				template += '<p><strong>{lang Equipment information}:</strong> ' + data.xtllq + '</p>';
			}
			if (data.message) {
				template += '<p><strong>评论内容:</strong> ' + data.message + '</p>';
			}
	
			layer.alert(template, {
				title: 'ID <strong>' + data.LAY_NUM + '</strong> 详情：'
			});
	
		// 标注选中样式
		obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');
		}
		// 搜索按钮功能
		$(document).on('click', '#search-btn', function() {
		// 获取搜索关键词
		var keyword = $('#keyword').val();
		// 刷新表格并传递搜索参数
		table.reloadData('table', {
		  where: { keyword: keyword},
		  page: {
			curr: 1 //重新从第 1 页开始
		  }
		});
	  });
	   // 重置按钮功能
	   $('#refreshsearch').click(function() {
        $('#keyword').val('');
		// 刷新表格
		table.reloadData('table', {
		  where: {type: type}, // 清空搜索参数
		  page: {
			curr: 1 //重新从第 1 页开始
		  }
		});
	  });
	  // 类型按钮功能
	  $(document).on('click', '.type-btn', function() {
		// 移除所有 .type-btn 的 active 类
		$('.type-btn').removeClass('active');
		// 为当前点击的按钮添加 active 类
		$(this).addClass('active');
		$('#keyword').val('');
		// 获取当前的 type 值
		operation = $(this).data('operation');
		type = $(this).data('type');
		// 刷新表格并传递 operation 参数
		table.reloadData('table', {
		  where: {type: type},
		  page: {
			curr: 1 //重新从第 1 页开始
		  }
		});
	  });
	});
</script>
<script src="dzz/comment/scripts/lyear_comment.js?{VERHASH}" type="text/javascript"></script> 
<script type="text/javascript" src="static/js/smilies.js?{VERHASH}"></script> 
<!-- The jQuery UI widget factory, can be omitted if jQuery UI is already included --> 
<script type="text/javascript" src="static/jquery_file_upload/jquery.ui.widget.js?{VERHASH}"></script> 
<script type="text/javascript" src="static/jquery_file_upload/jquery.iframe-transport.js?{VERHASH}"></script> 
<!-- The basic File Upload plugin --> 
<script type="text/javascript" src="static/jquery_file_upload/jquery.fileupload.js?{VERHASH}"></script> 
<script type="text/javascript" src="static/jquery_file_upload/jquery.fileupload-process.js?{VERHASH}"></script> 
<script type="text/javascript" src="static/jquery_file_upload/jquery.fileupload-validate.js?{VERHASH}"></script>
<!--{template lyear:footer_simple}-->